//负责创建schema对象和model对象
const mongoose = require('mongoose')

// 创建约束对象(schema)
const schema = new mongoose.Schema({
  advTitle: {
    type: String,
    required: true,
    unique: true,
  },
  advImg: {
    // 注意: 数据库无法存储文件,所以advImg存储的不是图片,而是访问这个图片的url地址
    type: String,
    required: true,
  },
  advCate: {
    type: String,
    required: true,
  },
  advLink: {
    type: String,
    required: true,
  },
  advInsertDate: {
    type: Date,
    default: Date.now(),
  },
  advUpdateDate: {
    type: Date,
    default: Date.now(),
  },
})

// 创建集合对象(model)
module.exports = mongoose.model('advs', schema)
